home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / UTILITY1 / MSWSRC35.ZIP / CMDWIND.CPP < prev    next >
C/C++ Source or Header  |  1993-10-12  |  10KB  |  404 lines

  1. #include "allwind.h"
  2.  
  3. #include <bwcc.h>
  4.  
  5. TMyCommandWindow::TMyCommandWindow(PTWindowsObject AParent, LPSTR ATitle)
  6. : TDialog(AParent, ATitle)
  7.    {
  8.    }
  9.  
  10. TMyCommandWindow::~TMyCommandWindow()
  11.    {
  12.    }
  13.  
  14. void TMyCommandWindow::GetWindowClass(WNDCLASS& WndClass)
  15.    {
  16.    TDialog::GetWindowClass( WndClass );
  17.    WndClass.lpszClassName = "Bordlg_Commander";
  18.    WndClass.hIcon = LoadIcon( GetApplication()->hInstance, "LogoIcon");
  19.    WndClass.lpfnWndProc = BWCCDefDlgProc;
  20.    }
  21.  
  22. void TMyCommandWindow::WMSize(RTMessage Msg)
  23.    { 
  24.    RECT TraceRect;
  25.    RECT ThisRect;
  26.    RECT EditRect;
  27.    int Xr;
  28.    int Yr;
  29.    int Ye;
  30.    int Yb;
  31.    int Xb;
  32.    
  33.    /* scale and pos. each sub-window in commander window based on its size */
  34.    
  35.    GetClientRect(TraceHWindow,&TraceRect);
  36.    GetClientRect(HWindow,&ThisRect);
  37.    GetClientRect(EditHWindow,&EditRect);
  38.    
  39.    Xr = ThisRect.right-ThisRect.left;
  40.    Yr = ThisRect.bottom-ThisRect.top;
  41.    Ye = EditRect.bottom-EditRect.top;
  42.    Yb = TraceRect.bottom-TraceRect.top;
  43.    Xb = TraceRect.right-TraceRect.left;
  44.    
  45.    SetWindowPos(ListHWindow,   NULL,        4,      1, Xr-Xb*2-10, Yr-Ye-5, 0);
  46.    SetWindowPos(EditHWindow,   NULL,        4,Yr-Ye-2, Xr-Xb*2-10,      Ye, 0);
  47.    
  48.    SetWindowPos(HaltHWindow,   NULL,Xr-Xb*2-4, Yb*0+1,       Xb*1,      Yb, 0);
  49.    SetWindowPos(TraceHWindow,  NULL,Xr-Xb*1-4, Yb*0+1,       Xb*1,      Yb, 0);
  50.    SetWindowPos(PauseHWindow,  NULL,Xr-Xb*2-4, Yb*1+1,       Xb*1,      Yb, 0);
  51.    SetWindowPos(StatusHWindow, NULL,Xr-Xb*1-4, Yb*1+1,       Xb*1,      Yb, 0);
  52.    SetWindowPos(YieldHWindow,  NULL,Xr-Xb*2-4, Yb*2+1,       Xb*1,      Yb, 0);
  53.    SetWindowPos(ResetHWindow,  NULL,Xr-Xb*1-4, Yb*2+1,       Xb*1,      Yb, 0);
  54.    
  55.    SetWindowPos(ExecuteHWindow,NULL,Xr-Xb*2-4,Yr-Ye-2,       Xb*2,      Ye, 0);
  56.    
  57.    }
  58.  
  59. void TMyCommandWindow::DoEditBox(RTMessage Msg)
  60.    { 
  61.    }
  62.  
  63. void TMyCommandWindow::DoListBox(RTMessage Msg)
  64.    { 
  65.    DWORD Idx;
  66.    
  67.    SelectedText[0] = '\0';
  68.    
  69.    /* if user clicks on a new selection copy it to edit box */
  70.    
  71.    if ( Msg.LP.Hi == LBN_SELCHANGE )
  72.       {
  73.       Idx = SendDlgItemMsg(ID_LISTBOX, LB_GETCURSEL, 0, 0L);
  74.       SendDlgItemMsg(ID_LISTBOX, LB_GETTEXT, (WORD)Idx, (DWORD)SelectedText);
  75.       SendDlgItemMsg(ID_EDITINPUT, WM_SETTEXT, 0, (DWORD)SelectedText);
  76.       }
  77.    
  78.    /* and if he double clicks then force a click on execute button */
  79.    
  80.    else if ( Msg.LP.Hi == LBN_DBLCLK )
  81.       {
  82.       DoButtonExecute(Msg);
  83.       }
  84.    
  85.    }
  86.  
  87. void do_execution(char * SelectedText2)
  88.    {
  89.    NODE *exec_list = NIL;
  90.    NODETYPES this_type;
  91.    int i;
  92.    char *c;
  93.    
  94.    /* if something there continue */
  95.    
  96.    if (strlen(SelectedText2) != 0)
  97.       {
  98.       
  99.       /* if executing then it's ok to halt */
  100.       
  101.       halt_flag++;
  102.       if (halt_flag < 1) halt_flag = 1;
  103.       
  104.       /* this code emulates the TTY model used in UCBLOGO main loop */
  105.       
  106.       this_type = STRING;
  107.       c = SelectedText2;
  108.       
  109.       /* do control character processing processing */
  110.       
  111.       for (c=SelectedText2;*c!='\0';c++)
  112.          {
  113.          if (*c == '\\')
  114.             {
  115.             strcpy(c,c+1);
  116.             if (*c)
  117.                {
  118.                if (*c == 'n') *c = '\n';
  119.                *c = setparity(*c);
  120.                }
  121.             this_type = BACKSLASH_STRING;
  122.             }
  123.          }
  124.       
  125.       //      sv_current_line = current_line;
  126.       //      current_line = NIL;
  127.       
  128.       /* turn text into a NODE and parse it */
  129.       
  130.       current_line = reref(current_line, make_strnode(SelectedText2, (char *)NULL, (int)strlen(SelectedText2), this_type, strnzcpy));
  131.       
  132.       exec_list = reref(exec_list, parser(current_line, TRUE));
  133.       
  134.       /* now process it */
  135.       
  136.       val_status = 0;
  137.       if (exec_list != NIL) eval_driver(exec_list);
  138.       
  139.       /* process special conditions */
  140.       
  141.       for (i=0;i<1;i++)
  142.          {
  143.          if (stopping_flag == THROWING)
  144.             {
  145.             if (compare_node(throw_node, Error, TRUE) == 0)
  146.                {
  147.                err_print();
  148.                }
  149.             else if (compare_node(throw_node, System, TRUE) == 0)
  150.                {
  151.                break;
  152.                }
  153.             else if (compare_node(throw_node, Toplevel, TRUE) != 0)
  154.                {
  155.                err_logo(NO_CATCH_TAG, throw_node);
  156.                err_print();
  157.                }
  158.             stopping_flag = RUN;
  159.             }
  160.          
  161.          if (stopping_flag == STOP || stopping_flag == OUTPUT)
  162.             {
  163.             print_node(stdout, make_static_strnode(
  164.             "You must be in a procedure to use OUTPUT or STOP.\n"));
  165.             stopping_flag = RUN;
  166.             }
  167.          }
  168.       
  169.       /* deallocate the line */
  170.       
  171.       current_line = reref(current_line, NIL);
  172.       
  173.       //      current_line = sv_current_line;
  174.       
  175.       /* this is a hack to force garbage collector to properly clean up */
  176.       
  177.       if (exec_list != NIL)
  178.          {
  179.          settype(exec_list,CONS);
  180.          exec_list = reref(exec_list, NIL);
  181.          }
  182.       
  183.       /* not ok to halt now */
  184.       
  185.       halt_flag--;
  186.       if (halt_flag < 0) halt_flag = 0;
  187.       }
  188.    
  189.    }
  190.  
  191. void TMyCommandWindow::DoButtonExecute(RTMessage Msg)
  192.    { 
  193.    char SelectedText2[MAX_BUFFER_SIZE];
  194.    
  195.    SelectedText2[0] = '\0';
  196.    
  197.    /* get what's in the edit box */
  198.    
  199.    getcombobox(SelectedText2);
  200.    
  201.    /* if real do something with it */
  202.    
  203.    if (strlen(SelectedText2))
  204.       {
  205.       
  206.       /* copy to list box for command recall */
  207.       
  208.       putcombobox(SelectedText2);
  209.       
  210.       /* if dribble then dribble */
  211.       
  212.       if (dribblestream != NULL) fprintf(dribblestream, "%s\n", SelectedText2);
  213.       
  214.       /* reset evaluation counter (call counter) and execute */
  215.       
  216.       eval_count = 0;
  217.       
  218.       do_execution(SelectedText2);
  219.       
  220.       }
  221.    
  222.    /* if we just poped up editor then don't set focus to commander input */
  223.    
  224.    if (!JustDidEdit) SetFocus(EditHWindow);
  225.    JustDidEdit = 0;
  226.    
  227.    }
  228.  
  229. void TMyCommandWindow::DoButtonStatus(RTMessage Msg)
  230.    { 
  231.    
  232.    /* toggle status state along with poping up and killing the status window */
  233.    
  234.    if (status_flag)
  235.       {
  236.       ((TMyWindow *)MainWindowx)->MyPopupStatusKill();
  237.       SetFocus(EditHWindow);
  238.       }
  239.    else
  240.       {
  241.       ((TMyWindow *)MainWindowx)->MyPopupStatus();
  242.       }
  243.    }
  244.  
  245. void TMyCommandWindow::DoButtonReset(RTMessage Msg)
  246.    { 
  247.    
  248.    /* just do a clear screen and return focus */
  249.    
  250.    lclearscreen();
  251.    SetFocus(EditHWindow);
  252.    }
  253.  
  254. void TMyCommandWindow::DoButtonYield(RTMessage Msg)
  255.    { 
  256.    
  257.    /* toggle yield state */
  258.    
  259.    if (yield_flag)
  260.       {
  261.       yield_flag = 0;
  262.       SendDlgItemMsg(ID_YIELD, WM_SETTEXT, 0, (DWORD)"Yield");
  263.       }
  264.    else
  265.       {
  266.       yield_flag = 1;
  267.       SendDlgItemMsg(ID_YIELD, WM_SETTEXT, 0, (DWORD)"NoYield");
  268.       }
  269.    SetFocus(EditHWindow);
  270.    }
  271.  
  272. void TMyCommandWindow::DoButtonPause(RTMessage Msg)
  273.    { 
  274.    
  275.    /* if ok to halt then it's ok to pause if we get here */
  276.    
  277.    SetFocus(EditHWindow);
  278.    if (halt_flag != 0) Time_To_Pause = 1;
  279.    }
  280.  
  281. // Will put pack later
  282. //
  283. //void do_pause_update(long arg)
  284.    //   { 
  285.    //   if (arg)
  286.       //      {
  287.       //      sprintf(YABuffer,"Pause-%d",(int)arg);
  288.       //      }
  289.    //   else
  290.       //      {
  291.       //      sprintf(YABuffer,"Pause");
  292.       //      }
  293.    //   ((TMyCommandWindow *)((TMyWindow *)MainWindowx)->CommandWindow)->
  294.    //   SendDlgItemMsg(ID_PAUSE, WM_SETTEXT, 0, (DWORD)YABuffer);
  295.    //   }
  296.  
  297. void TMyCommandWindow::DoButtonTrace(RTMessage Msg)
  298.    { 
  299.    
  300.    /* toggle trace state */
  301.    
  302.    if (traceflag)
  303.       {
  304.       traceflag = 0;
  305.       SendDlgItemMsg(ID_TRACE, WM_SETTEXT, 0, (DWORD)"Trace");
  306.       }
  307.    else
  308.       {
  309.       traceflag = 1;
  310.       SendDlgItemMsg(ID_TRACE, WM_SETTEXT, 0, (DWORD)"UnTrace");
  311.       }
  312.    SetFocus(EditHWindow);
  313.    }
  314.  
  315. void TMyCommandWindow::DoButtonHalt(RTMessage Msg)
  316.    { 
  317.    int i;
  318.    
  319.    for (i=1;i<